$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + '/manage/bzjList',
        datatype: "json",
        colModel: [
            { label: 'ID', name: 'id', width: 30, key: true },
            { label: '商品名称', name: 'name', width: 100 },
            {label:"平台",name:"platform",width: 40},
            {label:"发布者",name:"publisher",width: 60},
            {label:"审核类型",name:"type",width: 50,formatter: function(value, options, row){
                    if(value==0){  return  "手动审核";}
                    else if (value==1) {return "自动审核";}

                }},
            {label:"商品单价",name:"price",width: 50,formatter: function(value, options, row){
                    return  value+"元";

                }},
            {label:"佣金",name:"brokerage",width: 30,formatter: function(value, options, row){
                    return  value+"元";

                }},
            { label: '发布数量', name: 'num', width: 50 },
            {label:"保证金",name:"bail",width: 40,formatter: function(value, options, row){
                    return  value+"元";

                }},
            { label: '发布时间', name: 'createTime', width: 70,formatter: function(value, options, row){
                    return  parseTime(value);
                }},

            {label:"状态",name:"status",width: 50,formatter: function(value, options, row){
                    if (value==0){
                        return "商家待付款";
                    }else if (value==1) {
                        return "待审核";
                    }else if(value ==2){
                        return "已审核通过";
                    }else if(value ==3){
                        return "任务满额";
                    }else{
                        return "任务关闭";
                    }
                }},
            { label: '操作', name: 'status', width: 50, formatter: function(value, options, row){
                var str='<span class="btn btn-info btn-xs" onclick="getDetail('+row.id+')">查看</span>&nbsp;';
                if (value==1){
                    return str += '<span class="btn btn-warning btn-xs" onclick="pass('+row.id+')">确认</span>';
                }else{
                    return str;
                }
                }
            }
        ],
        viewrecords: true,
        height: 555,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "data.dataList",
            page: "data.currentPage",
            records: "data.totalNum",
            total: "data.total"
        },
        prmNames : {
            page:"pageNo",
            rows:"pageSize",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });

});
function pass(id){
    var data={"id":id};
    $.ajax({
        type: "POST",
        url: baseURL + "/manage/aduit",
        dataType: "json",
        contentType:"application/json",
        data:JSON.stringify(data),
        success: function(r){
            if (r.code===0) {
                var page = $("#jqGrid").jqGrid('getGridParam','page');
                $("#jqGrid").jqGrid('setGridParam',{
                    page:page
                }).trigger("reloadGrid");
            }else{
                alert(r.info);
            }

        }
    });
};
function getDetail(id) {
    layer.open({
        type: 2,
        title: '试用详情',
        shadeClose: true,
        shade: 0.8,
        area: ['90%', '90%'],
        content: weburl + '/manager/requertinfo.html?id='+id //iframe的url
    });
}
var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            key: null
        },
        showList: true,
        title: null
    },
    methods: {
        query: function () {
            vm.reload();
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'key': vm.q.key},
                page:page
            }).trigger("reloadGrid");
        }
    }
});
// var vm = new Vue({
//     el:'#rrapp',
//     data:{
//         q:{
//             key: null
//         },
//         showList: true,
//         title: null
//     },
//     methods: {
//         reload: function () {
//             vm.showList = true;
//             var page = $("#jqGrid").jqGrid('getGridParam','page');
//             $("#jqGrid").jqGrid('setGridParam',{
//                 postData:{'key': vm.q.key},
//                 page:page
//             }).trigger("reloadGrid");
//         }
//     }
// });